// 商品全部评价
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 下拉刷新，没有更多了  true
    noMore: false,
    comment: [],
    p: 1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var m_id = app.globalData.user.m_id;
    var p = this.data.p;
    wx.request({
      url: app.globalData.yuming + 'merchant.php/Api/Member/myAppraise',
      data: {
        m_id: m_id,
        p: p
      },
      header: {
        "content-type": "application/x-www-form-urlencoded"
      },
      method: "POST",
      success: function (res) {
        var comment = res.data.data.list;
        this.setData({
          comment: comment
        })
      }.bind(this),
      fail: function (res) {
        wx.showModal({
          title: '提示',
          content: res.data.message,
          showCancel: false
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    var m_id = app.globalData.user.m_id;
    var p = this.data.p;
    wx.request({
      url: app.globalData.yuming + 'merchant.php/Api/Member/myAppraise',
      data: {
        m_id: m_id,
        p: p
      },
      header: {
        "content-type": "application/x-www-form-urlencoded"
      },
      method: "POST",
      success: function (res) {
        var comment = res.data.data.list;
        this.setData({
          comment: comment
        })
      }.bind(this),
      fail: function (res) {
        wx.showModal({
          title: '提示',
          content: res.data.message,
          showCancel: false
        })
      }
    })
    wx.stopPullDownRefresh()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var noMore = this.data.noMore;
    if (noMore == false) {
      var p = this.data.p;
      p = p + 1;
      var m_id = app.globalData.user.m_id;
      var comment = this.data.comment;
      wx.request({
        url: app.globalData.yuming + 'merchant.php/Api/Member/myAppraise',
        data: {
          m_id: m_id,
          p: p
        },
        header: {
          "content-type": "application/x-www-form-urlencoded"
        },
        method: "POST",
        success: function (res) {
          var com = res.data.data.list;
          if (res.data.message != "已加载全部") {
            comment.push(com)
          } else {
            noMore = true
          }
          this.setData({
            comment: comment,
            p: p,
            noMore: noMore
          })
        }.bind(this),
        fail: function (res) {
          wx.showModal({
            title: '提示',
            content: res.data.message,
            showCancel: false
          })
        }
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: app.globalData.name,
      path: "/pages/shouye/shouye",
      imageUrl: app.globalData.headPic
    }
  }
})